<?php
namespace app\webapi\controller;

use think\Controller;
use Qiniu\Auth;
use Qiniu\Storage\UploadManager;
use think\Db;
use app\behavior;
use app\common\model;

class Index extends Controller
{
    public function index()
    {
        dump(input());die;
        $result = Db::name('areas')->page(1,20)->select();
        dump($result);die;
        $file = $_FILES['file']['tmp_name'];
        $accessKey = 'qDOqxXANLpIfIbIc0UwnvyRbl4HlC4bLQxdY5xC6';
        $secretKey = 'Clkk2Cg7tRieCCnAxF23MZnWuVXxKe41HBKoQ3Ik';
        $auth = new Auth($accessKey, $secretKey);
        // 空间名  https://developer.qiniu.io/kodo/manual/concepts
        $bucket = 'haibinketang-bucket';
        // 生成上传Token
        $token = $auth->uploadToken($bucket);
        // 构建 UploadManager 对象
        $uploadMgr = new UploadManager();

        $fileName = config('ios').'/'.rand(0000,9999).'.jpg';
        // 调用 UploadManager 的 putFile 方法进行文件的上传
        list($ret, $err) = $uploadMgr->putFile($token,$fileName,$file);
        echo "\n====> putFile result: \n";
        if($err !== null){
            return api_return($err);
//            $key = $err['key'];
//            $hash = $err['hash'];
        }else{
            return api_error('1001',$ret);
        }
        die;
        $url = 'http://ask.haibinjiaoyu.com/index.php?g=webapi&m=setting&a=course';
        $result = doCurl($url);
        return $result;
        $result = \think\Request::instance()->only(['id','name']);
        dump($result);die;
        $request = \think\Request::instance()->param('true');
        return api_return('xx',$request);
        echo config('default_return_type');
        echo config('test.name');
    }

    public function sms()
    {
//        $config = $config = [
//            'app_key'    => '23867005',
//            'app_secret' => 'c0da2173d6ab54a1c203688114ddb99b',
//            // 'sandbox'    => true,  // 是否为沙箱环境，默认false
//        ];
//        // 使用方法一
//        $client = new Client(new App($config));
//        $req    = new AlibabaAliqinFcSmsNumSend;
//
//        $req->setRecNum('13051637337')
//            ->setSmsParam([
//                'code' => rand(100000, 999999)
//            ]);
//        $req->setSmsFreeSignName('海滨课堂');
//        $req->setSmsTemplateCode('SMS_68085327');
//        $resp = $client->execute($req);
//        dump($resp);
        $model = new model\User;
        dump($model);
        $mobile = input('mobile');
        $params = input();
        $result = $this->validate($params,'User');
        dump($result);die;
        dump($params);die;
        $handel = new behavior\SendMessage();
        $result = $handel->send($mobile);
        dump($result);
    }

    public function getAuthToken(){

    }

}
